package LocalClassifier;

import java.util.ArrayList;

import Definitions.GraphClass;
import Definitions.NodeClass;
import Global.GlobalClass;
import InputPreparer.InputPreparationMethodInterface;
import Result.ResultClass;
import Sampling.SamplingAbstractClass;

public class AverageClass implements LocalClassifierInterface{

	String name;
	ArrayList <InputPreparationMethodInterface> inputPreparer;
	
	SamplingAbstractClass currentSampling;
	GlobalClass global;
	
	public AverageClass(String name, ArrayList<InputPreparationMethodInterface> inputPrep, SamplingAbstractClass currentSampling, GlobalClass global) 
	{
		// TODO Auto-generated constructor stub
		this.inputPreparer=inputPrep;
		this.name=name;
		this.currentSampling = currentSampling;
		this.global = global;
	}
	
	public double[] evaluate(NodeClass node, int whichStageIsRunning, String s) 
	{
		// TODO Auto-generated method stub
	
		System.out.println("Average ......Evaluate.....");
		ArrayList <Double> inputVector =this.getInformationVector(node, whichStageIsRunning);
		ArrayList <Double> resultVector=new ArrayList<Double>();
		int predictLabel=0;
		double max=0;
		
		//combine classifiers/
		for(int i=0; i<inputVector.size() ;i++)
		{
			double sum=0;
			int current=i;
			while(current<inputVector.size())
			{
				sum +=inputVector.get(current);
				current += global.classSize;
			}
			resultVector.add(sum);
		}
		//get max
		
		for(int i=0; i<global.classSize; i++)
		{
			if(resultVector.get(i)>max)
			{
				max=resultVector.get(i);
				predictLabel=i;
			}
		}
		
		System.out.println("Result vector::: ");
		
		for(double f: resultVector)
		{
			System.out.print(" "+ f);
		}
		
		System.out.println("Predict"+predictLabel);
		
		currentSampling.setClassLabelEstimated(node, predictLabel);
		//find max set
		return null;
	}

	public String getName() {
		// TODO Auto-generated method stub
		return name;
	}

	@Override
	public double[] getTrainRatios(String useSet) {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public void initialize(GraphClass g, ArrayList<Object> paramList) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void train(GraphClass g) {
		// TODO Auto-generated method stub
		 
	}
	 
	/**
	 **Method is dublicated prevent this find solution 
	 */
	private  ArrayList<Double> getInformationVector(NodeClass u, int whichNodesToUseForAggregation)
	{
	
		
		ArrayList<Double> input = new ArrayList<Double>(); 
		
		for(int i=0;  i<inputPreparer.size() ; i++)
		{
			
			ArrayList <Double> tempInput = inputPreparer.get(i).getInput(u, whichNodesToUseForAggregation);
			
			for(int j=0 ; j< tempInput.size() ; j++)
			{
				input.add(tempInput.get(j));
			}
			
			tempInput.clear();
		}
		return input;
	}

	@Override
	public void initialize(GraphClass g, ResultClass r) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public double[] getAlphaForSpecifiedDataSet(ArrayList<NodeClass> dataSet, int nodeIsInTestSetForTheFold) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void changeSecondLevelClassifierToBeUsed(String newClassifierName) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setSampling(SamplingAbstractClass sampling) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void train(GraphClass g, SamplingAbstractClass sampling) {
		// TODO Auto-generated method stub
		
	}
	
}
